<template>
  <div class="resume-upload">
    <h3>简历信息</h3>
    <!-- 简历名称 -->
    <el-form label-width="120px">
      <el-form-item label="简历名称">
        <el-input v-model="resumeName" placeholder="请输入简历名称"></el-input>
      </el-form-item>
    </el-form>
    
    <!-- 添加照片的框 -->
    <div class="photo-upload">
      <h3>上传照片</h3>
      <input type="file" @change="handleFileChange">
      <div v-if="photoUrl" class="photo-preview">
        <div class="photo-container">
          <img :src="photoUrl" alt="photo">
        </div>
        <el-button type="text" @click="removePhoto">删除</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      resumeName: '',
      photoUrl: ''
    };
  },
  methods: {
    handleFileChange(event) {
      const file = event.target.files[0];
      if (file) {
        // 使用FileReader读取文件
        const reader = new FileReader();
        reader.onload = (e) => {
          this.photoUrl = e.target.result;
        };
        reader.readAsDataURL(file);
      }
    },
    removePhoto() {
      this.photoUrl = '';
    }
  }
};
</script>

<style scoped>
.resume-upload {
  margin-bottom: 20px;
}
.photo-upload {
  margin-top: 20px;
}
.photo-preview {
  margin-top: 10px;
}
.photo-container {
  width: 1in;
  height: 1in;
  overflow: hidden;
}
.photo-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>
